﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MusicService
{
    public partial class MusicService:ISingerGenreService
    {
        public bool addSingerGenre(string singerID, string genreID)
        {
            bool flag = false;
            SingerGenre singerGenre = new SingerGenre();
            try
            {
                singerGenre.SingerID = singerID;
                singerGenre.GenreID = genreID;
                dc.SingerGenres.InsertOnSubmit(singerGenre);
                dc.SubmitChanges();
                flag = true;
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public bool removeSingerGenre(string singerID, string genreID)
        {
            bool flag = false;
            try
            {
                SingerGenre singerGenre = dc.SingerGenres.Single(tmp => tmp.SingerID.Equals(singerID) && 
                    tmp.GenreID.Equals(genreID));
                if (singerGenre != null)
                {
                    dc.SingerGenres.DeleteOnSubmit(singerGenre);
                    dc.SubmitChanges();
                    flag = true;
                }
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public bool updateSingerGenre(string singerID, string genreID)
        {
            bool flag = false;
            try
            {
                SingerGenre singerGenre = dc.SingerGenres.Single(tmp => tmp.SingerID.Equals(singerID) && 
                    tmp.GenreID.Equals(genreID));
                if (singerGenre != null)
                {
                    singerGenre.SingerID = singerID;
                    singerGenre.GenreID = genreID;
                    dc.SubmitChanges();
                    flag = true;
                }
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public List<SingerGenre> getAllSingerGenre()
        {
            var list = from sg in dc.SingerGenres select sg;
            return list.ToList();
        }

        public SingerGenre getSingerGenreByID(string singerID, string genreID)
        {
            SingerGenre singerGenre = dc.SingerGenres.Single(tmp => tmp.SingerID.Equals(singerID) && 
                tmp.GenreID.Equals(genreID));
            return singerGenre;
        }
    }
}